import React, { Component } from 'react';
import YwxNavBar from '../../components/common/YwxNavBar/YwxNavBar';
import AuditList from '../../components/Audit/AuditList/AuditList';

export default class Audit extends Component {

    constructor(props) {
        super(props);
        this.state = {
            pageSize: 15,
            list: [],
            nomore: false
        }
    }

    componentDidMount() {
        this.page = 1;
        this.fetchData(list => {
            this.setState({
                list: list
            })
        })
    };

    fetchData = (callback) => {
        React.$utils.request({
            url: '/app/commissionAudit',
            params: {
                pageNo: this.page || 1,
                limit: this.state.pageSize
            }
        }).then(res => {
            this.setState({
                nomore: res.length === 0
            });
            callback && callback(res);
        })
    }

    onRefresh = () => {
        this.page = 1;
        this.fetchData(list => {
            this.setState({
                list: list
            })
        })
    }

    onEndReached = () => {
        this.page++;
        this.fetchData(list => {
            this.setState({
                list: this.state.list.concat(list)
            })
        })
    }

    render() {
        return (
            <div className='audit'>
                <YwxNavBar>佣金审核</YwxNavBar>
                <AuditList
                    noMore={this.state.nomore}
                    list={this.state.list}
                    onRefresh={this.onRefresh}
                    onEndReached={this.onEndReached}
                    pageSize={this.state.pageSize} />
            </div>
        );
    }
}